import type { DescData } from '@arco-design/web-vue/es/descriptions/interface'
import axios from 'axios'
import qs from 'query-string'

export interface PageQuery{
  current: number
  pageSize: number
  trueName?: string
  mobile?: string
  sex?: boolean
  status?: boolean
  email?: string
}

export interface MemberRecord {
  userId: number,
  trueName: string | null
  mobile: string,
  sex: boolean,
  status: boolean,
  email: string | null
}

export interface MemberPageRes{
  list: MemberRecord[],
  total: number
}

export interface MemberDetail extends MemberRecord {
  telephone?: string | null
  area?: string | null
  contactAddr?: string | null
  qq?: string | null
  birthday?: string | null
  groupId?: number
  exp?: number
  point?: number
  messageIds?: string | null
  time?: string | null
  zip?: string | null
  prop?: string | null
  balance?: number
  lastLogin?: string | null
  custom?: string | null
  openId?: string | null
  avatar?: string | null
}

// 分页查询会员
export function queryMemberPage(params: PageQuery) {
  return axios.get<MemberPageRes>('/api/member/page',{
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj)
    },
  })
}

// 获取会员详情
export function getMemberDetail(id: number) {
  return axios.get<MemberDetail>(`/api/member/${id}`)
}

// 编辑会员信息
export function updateMember(data: MemberDetail) {
  return axios.put('/api/member', data)
}

// 启用/禁用会员
export function toggleMemberStatus(id: number) {
  return axios.put(`/api/member/enable/${id}`)
}

// 删除会员
export function deleteMember(ids: number[]) {
  return axios.delete('/api/member', {
    data: ids
  })
}